const db = require('../db/index');
const DataTypes = require('sequelize');
const Roles = require('./Roles');
const Drives = require('./Drives');
const Use = require('./Use');
/**es6继承 */
class Admin extends DataTypes.Model {}
Admin.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        username: {
            type: DataTypes.STRING,
            allowNull: false
        },
        phone: {
            type: DataTypes.BIGINT,
            allowNull: false
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false
        },
        avatar: {
            type: DataTypes.STRING,
            allowNull: false
        },
        role_id: {
            type: DataTypes.INTEGER,
            allowNull: false
        },
        isAdmin: {
            type: DataTypes.BOOLEAN,
            comment: '1 true 0false 是否超级管理员',
            defaultValue: 0,
            allowNull: false
        },
        contract: {
            type: DataTypes.DECIMAL(10, 2),
            comment: '合同比例',
            defaultValue: 0,
            allowNull: false
        },
        money: {
            type: DataTypes.DECIMAL(10, 2),
            comment: '金钱',
            defaultValue: 0,
            allowNull: false
        },
        status: {
            type: DataTypes.BOOLEAN,
            comment: '1 启用 0禁用',
            allowNull: false
        }
    },
    {
        tableName: 'admins',
        modelName: 'admin',
        sequelize: db
    }
);
// Admin.sync({ force: true });
Admin.hasMany(Use['default'], {
    as: 'merchantData',
    foreignKey: 'merchantId'
});
Admin.hasMany(Drives['default'], {
    as: 'drivesData',
    foreignKey: 'merchantId'
});
Admin.belongsTo(Roles['default'], { foreignKey: 'role_id' });
exports['default'] = Admin;
